package helper

import (
	"github.com/gin-gonic/gin"
	"matcher/pkg/lib/merror"
	"matcher/pkg/types"
)

func Success(ctx *gin.Context, data interface{}, p *types.Paginator) {
	if data == nil {
		data = types.Any{}
	}

	if p == nil {
		ctx.JSON(200, types.Any{
			"payload": data,
		})
	} else {
		ctx.JSON(200, types.Any{
			"payload":   data,
			"paginator": p,
		})
	}

}

func Error(ctx *gin.Context, err *merror.Error) {
	ctx.JSON(400, err)
}
